package com.wanmao.test.framgent;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
//import android.support.annotation.RequiresApi;
//import android.support.v4.content.ContextCompat;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;


import com.wanmao.test.R;
import com.wanmao.test.adapter.RankAdapter;
import com.wanmao.test.model.RankBean;

import java.util.Arrays;


public class Framgent_Test_Rank extends Fragment {
    TextView tv_task;
    TextView tv_question;
    TextView tv_warning;
    ListView listView;
    ImageView img_back;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_rank, container, false);
        intenView(view);
        return view;

    }

    private void intenView(View view) {
        tv_task = (TextView)view.findViewById(R.id.tv_task);
        tv_question = (TextView)view.findViewById(R.id.tv_question);
        tv_warning =(TextView) view.findViewById(R.id.tv_warning);
        listView = (ListView) view.findViewById(R.id.listview);
        img_back = (ImageView) view.findViewById(R.id.img_back);

        tv_task.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                changeTaskView();
                setTaskDate();
            }
        });

        tv_question.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                changeQuestionView();
                setQuestionDate();
            }
        });

        tv_warning.setOnClickListener(new View.OnClickListener() {
//            @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View view) {
                changeWarningView();
                setWarningDate();
            }
        });

        setTaskDate();
    }

    private void changeWarningView() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                tv_warning.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.round_bg_search_blue));
            }
        }
        tv_warning.setTextColor(Color.WHITE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv_task.setBackground(null);
        }
        tv_task.setTextColor(Color.parseColor("#919191"));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv_question.setBackground(null);
        }
        tv_question.setTextColor(Color.parseColor("#919191"));
    }

    /**
     * 选中问题反馈改变View
     */
    private void changeQuestionView() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                tv_question.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.round_bg_search_blue));
            }
        }
        tv_question.setTextColor(Color.WHITE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv_task.setBackground(null);
        }
        tv_task.setTextColor(Color.parseColor("#919191"));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv_warning.setBackground(null);
        }
        tv_warning.setTextColor(Color.parseColor("#919191"));
    }

    private void changeTaskView() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                tv_task.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.round_bg_search_blue));
            }
        }
        tv_task.setTextColor(Color.WHITE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv_question.setBackground(null);
        }
        tv_question.setTextColor(Color.parseColor("#919191"));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv_warning.setBackground(null);
        }
        tv_warning.setTextColor(Color.parseColor("#919191"));
    }

    private void setTaskDate() {
        listView.setAdapter(new RankAdapter(Arrays.asList(new RankBean("刘喆", "城南", "15"), new RankBean("胡志刚", "城东", "13"), new RankBean("牛原", "宁河", "11"),
                new RankBean("魏菊芳", "电科院", "9"), new RankBean("张奇", "滨海", "7"), new RankBean("白婧婧", "武清", "6"),
                new RankBean("张春辉", "电科院", "5"), new RankBean("孙阔", "城西", "4"), new RankBean("徐福", "宝坻", "3"),
                new RankBean("周森", "蓟县", "2")), getActivity()));
    }

    /**
     * 设置问题反馈数据
     */
    private void setQuestionDate() {
        listView.setAdapter(new RankAdapter(Arrays.asList(new RankBean("胡志刚", "城东", "11"), new RankBean("周森", "蓟县", "10"), new RankBean("牛原", "宁河", "9"),
                new RankBean("魏菊芳", "电科院", "9"), new RankBean("张奇", "滨海", "8"), new RankBean("白婧婧", "武清", "8"),
                new RankBean("徐福", "宝坻", "8"), new RankBean("孙阔", "城西", "7"), new RankBean("张春辉", "电科院", "6"),
                new RankBean("刘喆", "城南", "5")), getActivity()));
    }

    /**
     * 设置告警数据
     */
    private void setWarningDate() {
        listView.setAdapter(new RankAdapter(Arrays.asList(new RankBean("魏菊芳", "电科院", "13"), new RankBean("白婧婧", "武清", "12"), new RankBean("牛原", "宁河", "11"),
                new RankBean("胡志刚", "城东", "9"), new RankBean("孙阔", "城西", "8"), new RankBean("刘喆", "城南", "7"),
                new RankBean("徐福", "宝坻", "5"), new RankBean("周森", "蓟县", "4"), new RankBean("张春辉", "电科院", "3"),
                new RankBean("张奇", "滨海", "2")), getActivity()));
    }



}
